package day4.homework;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
//设计一个类简单的类 有参构造方法私有化了  通过反射使用有参构造把该对象创建出来
public class TestUser {
    public Integer id;
    public String name;

    private TestUser(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class c = Class.forName("day4.homework.TestUser");
        Constructor con = c.getDeclaredConstructor(Integer.class,String.class);
        con.setAccessible(true);
        TestUser u = (TestUser) con.newInstance(1,"陈平安");
        System.out.println(u);
    }
}
